<?php 
// cps规则
namespace Admin\Model;
use Think\Model;
class CpsModel extends Model {
	 protected $tableName = 'cps_rule';
	 protected $_validate = array(
      
     
   );


	public function checkAddCps($start_flow)
	{
		if (C('IS_FALSE_DEL')) {
			$where['is_delete']='0';
		}else{
			$where=[];
		}

		$count=$this->where(['session_id'=>session_id()])->where($where)->count();

		if ($count==0) {
			return true;
		}

		$max=$this->where(['session_id'=>session_id()])->where($where)->max('end_flow');
		if ($start_flow<=$max) {
			 return false;
		}else{
			return true;
		}

	}

	public function checkSaveCps($ad_id,$start_flow)
	{
		if (C('IS_FALSE_DEL')) {
			$where['is_delete']='0';
		}else{
			$where=[];
		}

		$count=$this->where(['ad_id'=>$ad_id])->where($where)->count();

		if ($count==0) {
			return true;
		}

		$max=$this->where(['ad_id'=>$ad_id])->where($where)->max('end_flow');
		if ($start_flow<=$max) {
			 return false;
		}else{
			return true;
		}

	}

	 
}